﻿namespace HRM.CORE.REPORT
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraLayout;
    using DevExpress.XtraLayout.Utils;
    using Microsoft.VisualBasic;
    using Common.Report;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms; using Common;

    public class xfmListWork : XtraForm
    {
        private SimpleButton btCancel;
        private SimpleButton btPrint;
        private ComboBoxEdit cboStatus;
        private ComboBoxEdit cboTime;
        private IContainer components = null;
        private DateEdit dtBeginDate;
        private DateEdit dtEndDate;
        private EmptySpaceItem emptySpaceItem1;
        private GroupControl groupControl2;
        private DevExpress.Utils.ImageCollection imageCollection1;
        private LayoutControl layoutControl1;
        private LayoutControlGroup layoutControlGroup1;
        private LayoutControlItem layoutControlItem1;
        private LayoutControlItem layoutControlItem2;
        private LayoutControlItem layoutControlItem3;
        private LayoutControlItem layoutControlItem4;
        private LayoutControlItem layoutControlItem5;
        private int m_Status = -1;
        private TimeEdit teYear;

        public xfmListWork()
        {
            this.InitializeComponent();
            this.InitData();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btPrint_Click(object sender, EventArgs e)
        {
            rptListWork work;
            this.m_Status = this.cboStatus.SelectedIndex - 1;
            xfmReport report = new xfmReport();
            if (this.cboTime.SelectedIndex == 0)
            {
                work = new rptListWork("", this.dtBeginDate.DateTime, this.dtEndDate.DateTime, this.m_Status);
            }
            else
            {
                work = new rptListWork(this.cboTime.SelectedItem.ToString(), this.dtBeginDate.DateTime, this.dtEndDate.DateTime, this.m_Status);
            }
            report.SetTitle("Danh S\x00e1ch C\x00f4ng Việc");
            report.ShowPrintPreview(work);
        }

        private void cboTime_SelectedIndexChanged(object sender, EventArgs e)
        {
            int year = DateTime.Parse(this.teYear.EditValue.ToString()).Year;
            if (this.cboTime.SelectedIndex == 0)
            {
                this.dtBeginDate.Enabled = true;
                this.dtEndDate.Enabled = true;
            }
            else
            {
                this.dtBeginDate.Enabled = false;
                this.dtEndDate.Enabled = false;
                if (this.cboTime.SelectedIndex == 1)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 1, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(3).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 2)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 4, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(3).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 3)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 7, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(3).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 4)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 10, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(3).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 5)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 1, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 6)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 2, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 7)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 3, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 8)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 4, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 9)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 5, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 10)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 6, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 11)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 7, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 12)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 8, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 13)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 9, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 14)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 10, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 15)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 11, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
                else if (this.cboTime.SelectedIndex == 0x10)
                {
                    this.dtBeginDate.DateTime = new DateTime(year, 12, 1);
                    this.dtEndDate.DateTime = this.dtBeginDate.DateTime.AddMonths(1).AddDays(-1.0);
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitData()
        {
            DateTime now;
            this.teYear.EditValue = DateTime.Now;
            try
            {
                now = DateAndTime.DateAdd(DateInterval.Month, -3.0, DateTime.Now);
            }
            catch
            {
                now = DateTime.Now;
            }
            this.dtBeginDate.EditValue = now;
            this.dtEndDate.EditValue = DateTime.Now;
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmListWork));
            this.btPrint = new SimpleButton();
            this.imageCollection1 = new DevExpress.Utils.ImageCollection(this.components);
            this.btCancel = new SimpleButton();
            this.groupControl2 = new GroupControl();
            this.layoutControl1 = new LayoutControl();
            this.dtEndDate = new DateEdit();
            this.dtBeginDate = new DateEdit();
            this.cboTime = new ComboBoxEdit();
            this.cboStatus = new ComboBoxEdit();
            this.layoutControlGroup1 = new LayoutControlGroup();
            this.layoutControlItem1 = new LayoutControlItem();
            this.layoutControlItem2 = new LayoutControlItem();
            this.layoutControlItem3 = new LayoutControlItem();
            this.layoutControlItem4 = new LayoutControlItem();
            this.emptySpaceItem1 = new EmptySpaceItem();
            this.teYear = new TimeEdit();
            this.layoutControlItem5 = new LayoutControlItem();
            this.imageCollection1.BeginInit();
            this.groupControl2.BeginInit();
            this.groupControl2.SuspendLayout();
            this.layoutControl1.BeginInit();
            this.layoutControl1.SuspendLayout();
            this.dtEndDate.Properties.VistaTimeProperties.BeginInit();
            this.dtEndDate.Properties.BeginInit();
            this.dtBeginDate.Properties.VistaTimeProperties.BeginInit();
            this.dtBeginDate.Properties.BeginInit();
            this.cboTime.Properties.BeginInit();
            this.cboStatus.Properties.BeginInit();
            this.layoutControlGroup1.BeginInit();
            this.layoutControlItem1.BeginInit();
            this.layoutControlItem2.BeginInit();
            this.layoutControlItem3.BeginInit();
            this.layoutControlItem4.BeginInit();
            this.emptySpaceItem1.BeginInit();
            this.teYear.Properties.BeginInit();
            this.layoutControlItem5.BeginInit();
            base.SuspendLayout();
            this.btPrint.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btPrint.ImageIndex = 0;
            this.btPrint.ImageList = this.imageCollection1;
            this.btPrint.Location = new Point(0x72, 0xd1);
            this.btPrint.Name = "btPrint";
            this.btPrint.Size = new Size(0x5f, 0x18);
            this.btPrint.TabIndex = 2;
            this.btPrint.Text = "Xem trước";
            this.btPrint.Click += new EventHandler(this.btPrint_Click);
            this.imageCollection1.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection1.ImageStream");
            this.imageCollection1.Images.SetKeyName(0, "ico_alpha_Search_16x16.png");
            this.imageCollection1.Images.SetKeyName(1, "ico_alpha_Delete_16x16.png");
            this.imageCollection1.Images.SetKeyName(2, "document2.png");
            this.imageCollection1.Images.SetKeyName(3, "open-16x16.png");
            this.btCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btCancel.ImageIndex = 1;
            this.btCancel.ImageList = this.imageCollection1;
            this.btCancel.Location = new Point(0xdb, 0xd1);
            this.btCancel.Name = "btCancel";
            this.btCancel.Size = new Size(0x5f, 0x18);
            this.btCancel.TabIndex = 3;
            this.btCancel.Text = "Tho\x00e1t";
            this.btCancel.Click += new EventHandler(this.btCancel_Click);
            this.groupControl2.Controls.Add(this.layoutControl1);
            this.groupControl2.Location = new Point(12, 12);
            this.groupControl2.Name = "groupControl2";
            this.groupControl2.Size = new Size(300, 0xb9);
            this.groupControl2.TabIndex = 6;
            this.groupControl2.Text = "C\x00e1c tham số";
            this.layoutControl1.Controls.Add(this.teYear);
            this.layoutControl1.Controls.Add(this.dtEndDate);
            this.layoutControl1.Controls.Add(this.dtBeginDate);
            this.layoutControl1.Controls.Add(this.cboTime);
            this.layoutControl1.Controls.Add(this.cboStatus);
            this.layoutControl1.Dock = DockStyle.Fill;
            this.layoutControl1.Location = new Point(2, 0x16);
            this.layoutControl1.Name = "layoutControl1";
            this.layoutControl1.Root = this.layoutControlGroup1;
            this.layoutControl1.Size = new Size(0x128, 0xa1);
            this.layoutControl1.TabIndex = 30;
            this.layoutControl1.Text = "layoutControl1";
            this.dtEndDate.EditValue = null;
            this.dtEndDate.Location = new Point(0x45, 0x7d);
            this.dtEndDate.Name = "dtEndDate";
            this.dtEndDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtEndDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtEndDate.Size = new Size(0xd7, 20);
            this.dtEndDate.StyleController = this.layoutControl1;
            this.dtEndDate.TabIndex = 0x2b;
            this.dtBeginDate.EditValue = null;
            this.dtBeginDate.Location = new Point(0x45, 0x5d);
            this.dtBeginDate.Name = "dtBeginDate";
            this.dtBeginDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtBeginDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtBeginDate.Size = new Size(0xd7, 20);
            this.dtBeginDate.StyleController = this.layoutControl1;
            this.dtBeginDate.TabIndex = 0x2a;
            this.cboTime.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.cboTime.EditValue = "Chọn theo ng\x00e0y";
            this.cboTime.Location = new Point(0x45, 0x3d);
            this.cboTime.Name = "cboTime";
            this.cboTime.Properties.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.cboTime.Properties.Appearance.Options.UseFont = true;
            this.cboTime.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cboTime.Properties.Items.AddRange(new object[] { 
                "Chọn theo ng\x00e0y", "Qu\x00fd I", "Qu\x00fd II", "Qu\x00fd III", "Qu\x00fd IV", "Th\x00e1ng 1", "Th\x00e1ng 2", "Th\x00e1ng 3", "Th\x00e1ng 4", "Th\x00e1ng 5", "Th\x00e1ng 6", "Th\x00e1ng 7", "Th\x00e1ng 8", "Th\x00e1ng 9", "Th\x00e1ng 10", "Th\x00e1ng 11", 
                "Th\x00e1ng 12"
             });
            this.cboTime.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
            this.cboTime.Size = new Size(0x80, 20);
            this.cboTime.StyleController = this.layoutControl1;
            this.cboTime.TabIndex = 0x29;
            this.cboTime.SelectedIndexChanged += new EventHandler(this.cboTime_SelectedIndexChanged);
            this.cboStatus.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.cboStatus.EditValue = "Tất cả";
            this.cboStatus.Location = new Point(0x45, 0x10);
            this.cboStatus.Name = "cboStatus";
            this.cboStatus.Properties.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.cboStatus.Properties.Appearance.Options.UseFont = true;
            this.cboStatus.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cboStatus.Properties.Items.AddRange(new object[] { "Tất cả", "Chưa bắt đầu", "Đang thực hiện", "Đ\x00e3 ho\x00e0n th\x00e0nh", "Đ\x00e3 hũy bỏ" });
            this.cboStatus.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
            this.cboStatus.Size = new Size(0xd7, 20);
            this.cboStatus.StyleController = this.layoutControl1;
            this.cboStatus.TabIndex = 40;
            this.layoutControlGroup1.CustomizationFormText = "layoutControlGroup1";
            this.layoutControlGroup1.EnableIndentsWithoutBorders = DefaultBoolean.True;
            this.layoutControlGroup1.GroupBordersVisible = false;
            this.layoutControlGroup1.Items.AddRange(new BaseLayoutItem[] { this.layoutControlItem1, this.layoutControlItem2, this.layoutControlItem3, this.layoutControlItem4, this.emptySpaceItem1, this.layoutControlItem5 });
            this.layoutControlGroup1.Location = new Point(0, 0);
            this.layoutControlGroup1.Name = "layoutControlGroup1";
            this.layoutControlGroup1.Size = new Size(0x128, 0xa1);
            this.layoutControlGroup1.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 0, 0);
            this.layoutControlGroup1.Text = "layoutControlGroup1";
            this.layoutControlGroup1.TextVisible = false;
            this.layoutControlItem1.Control = this.cboStatus;
            this.layoutControlItem1.CustomizationFormText = "Trạng th\x00e1i:";
            this.layoutControlItem1.Location = new Point(0, 0);
            this.layoutControlItem1.Name = "layoutControlItem1";
            this.layoutControlItem1.Size = new Size(0x114, 0x20);
            this.layoutControlItem1.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 4, 4);
            this.layoutControlItem1.Text = "Trạng th\x00e1i:";
            this.layoutControlItem1.TextSize = new Size(0x35, 13);
            this.layoutControlItem2.Control = this.cboTime;
            this.layoutControlItem2.CustomizationFormText = "Chọn đợt:";
            this.layoutControlItem2.Location = new Point(0, 0x2d);
            this.layoutControlItem2.Name = "layoutControlItem2";
            this.layoutControlItem2.Size = new Size(0xbd, 0x20);
            this.layoutControlItem2.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 4, 4);
            this.layoutControlItem2.Text = "Chọn đợt:";
            this.layoutControlItem2.TextSize = new Size(0x35, 13);
            this.layoutControlItem3.Control = this.dtBeginDate;
            this.layoutControlItem3.CustomizationFormText = "Từ ng\x00e0y:";
            this.layoutControlItem3.Location = new Point(0, 0x4d);
            this.layoutControlItem3.Name = "layoutControlItem3";
            this.layoutControlItem3.Size = new Size(0x114, 0x20);
            this.layoutControlItem3.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 4, 4);
            this.layoutControlItem3.Text = "Từ ng\x00e0y:";
            this.layoutControlItem3.TextSize = new Size(0x35, 13);
            this.layoutControlItem4.Control = this.dtEndDate;
            this.layoutControlItem4.CustomizationFormText = "Đến ng\x00e0y:";
            this.layoutControlItem4.Location = new Point(0, 0x6d);
            this.layoutControlItem4.Name = "layoutControlItem4";
            this.layoutControlItem4.Size = new Size(0x114, 0x20);
            this.layoutControlItem4.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 4, 4);
            this.layoutControlItem4.Text = "Đến ng\x00e0y:";
            this.layoutControlItem4.TextSize = new Size(0x35, 13);
            this.emptySpaceItem1.CustomizationFormText = "emptySpaceItem1";
            this.emptySpaceItem1.Location = new Point(0, 0x20);
            this.emptySpaceItem1.Name = "emptySpaceItem1";
            this.emptySpaceItem1.Size = new Size(0x114, 13);
            this.emptySpaceItem1.Text = "emptySpaceItem1";
            this.emptySpaceItem1.TextSize = new Size(0, 0);
            this.teYear.EditValue = new DateTime(0x7dc, 6, 0x1c, 0, 0, 0, 0);
            this.teYear.Location = new Point(0xe7, 0x3d);
            this.teYear.Name = "teYear";
            this.teYear.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.teYear.Properties.Mask.EditMask = "yyyy";
            this.teYear.Size = new Size(0x35, 20);
            this.teYear.StyleController = this.layoutControl1;
            this.teYear.TabIndex = 0x2c;
            this.teYear.EditValueChanged += new EventHandler(this.teYear_EditValueChanged);
            this.layoutControlItem5.Control = this.teYear;
            this.layoutControlItem5.CustomizationFormText = "Năm:";
            this.layoutControlItem5.Location = new Point(0xbd, 0x2d);
            this.layoutControlItem5.Name = "layoutControlItem5";
            this.layoutControlItem5.Size = new Size(0x57, 0x20);
            this.layoutControlItem5.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 4, 4);
            this.layoutControlItem5.Text = "Năm:";
            this.layoutControlItem5.TextAlignMode = TextAlignModeItem.AutoSize;
            this.layoutControlItem5.TextSize = new Size(0x19, 13);
            this.layoutControlItem5.TextToControlDistance = 5;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x144, 0xf2);
            base.Controls.Add(this.groupControl2);
            base.Controls.Add(this.btCancel);
            base.Controls.Add(this.btPrint);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmListWork";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "T\x00f9y Chọn In";
            this.imageCollection1.EndInit();
            this.groupControl2.EndInit();
            this.groupControl2.ResumeLayout(false);
            this.layoutControl1.EndInit();
            this.layoutControl1.ResumeLayout(false);
            this.dtEndDate.Properties.VistaTimeProperties.EndInit();
            this.dtEndDate.Properties.EndInit();
            this.dtBeginDate.Properties.VistaTimeProperties.EndInit();
            this.dtBeginDate.Properties.EndInit();
            this.cboTime.Properties.EndInit();
            this.cboStatus.Properties.EndInit();
            this.layoutControlGroup1.EndInit();
            this.layoutControlItem1.EndInit();
            this.layoutControlItem2.EndInit();
            this.layoutControlItem3.EndInit();
            this.layoutControlItem4.EndInit();
            this.emptySpaceItem1.EndInit();
            this.teYear.Properties.EndInit();
            this.layoutControlItem5.EndInit();
            base.ResumeLayout(false);
        }

        private void teYear_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                int year = DateTime.Parse(this.teYear.EditValue.ToString()).Year;
                this.dtBeginDate.DateTime = new DateTime(year, this.dtBeginDate.DateTime.Month, this.dtBeginDate.DateTime.Day);
                this.dtEndDate.DateTime = new DateTime(year, this.dtEndDate.DateTime.Month, this.dtEndDate.DateTime.Day);
            }
            catch
            {
            }
        }
    }
}

